<?php
namespace Muyuxuan\ThreePayment\three\bct\tool\Demo;
/* 宝付账簿个人/机构账户余额查询接口
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

use Muyuxuan\ThreePayment\three\bct\tool\SecurityUtil\NewRsaUtil;
use Muyuxuan\ThreePayment\three\bct\tool\Util\HttpClient;
use Muyuxuan\ThreePayment\three\bct\tool\Util\Log;
use Muyuxuan\ThreePayment\three\bct\tool\Util\Tools;

require_once '../Init/init.php';

Log::EchoFormat("==========================");
Log::EchoFormat("宝付账簿个人/机构账户余额查询接口");
Log::EchoFormat("==========================");


/* Header 参数*/
$HeaderPost = array();
$HeaderPost["memberId"] = $GLOBALS["Member_Id"];//宝付提供给商户的唯一编号
$HeaderPost["terminalId"] = $GLOBALS["Terminal_Id"];
$HeaderPost["serviceTp"] = "T-1001-013-06";//报文编号
$HeaderPost["verifyType"] = "1";//加密方式目前只有1种，请填：1

$contentData = array();       
$contentData["header"] = $HeaderPost;


$BodyData = array();  
$BodyData["version"] = "4.0.0";//版本号
$BodyData["accType"] = "1";//账户类型:1个人,2商户

$BodyData["contractNo"] = "CP610000000000188888";//客户账户号


$contentData["body"] = $BodyData;

$JsonObject = json_encode($contentData);
Log::EchoFormat("JSON：".$JsonObject);

$Data_Content = NewRsaUtil::encryptByPfx($JsonObject,$GLOBALS["PFX_FILE_PATH"],$GLOBALS["Key_Pwd"]);
$HeaderPost["content"] = $Data_Content;

$PostString  =  HttpClient::Post($HeaderPost, Tools::getUrl($HeaderPost["serviceTp"]),"json");

Log::EchoFormat("返回：".$PostString);

IF(empty($PostString)){
    throw new \Exception("返回异常！");
}
$RPostString = NewRsaUtil::decrptByPub($PostString,$GLOBALS["CER_FILE_PATH"]);

Log::EchoFormat("解密明文：".$RPostString);